<template>
  <!-- 详情开始 -->
  <a-modal
    :maskClosable="false"
    title="合同变更记录"
    :width="1350"
    :bodyStyle="{
      padding: '0 24px'
    }"
    :visible="visible"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card
      :bordered="false"
      :bodyStyle="{
        padding: '10px 24px'
      }">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="handleQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="单据编号" :labelCol="labelCol">
                <j-input placeholder="请输入单据编号" v-model="queryParam.htbh"></j-input>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="合同名称" :labelCol="labelCol">
                <j-input placeholder="请输入合同名称" v-model="queryParam.htmc"></j-input>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目编号" :labelCol="labelCol">
                <j-input placeholder="请输入项目编号" v-model="queryParam.xmbh"></j-input>
              </a-form-item>
            </a-col>

            <template v-if="toggleSearchStatus">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item
                  label="项目名称"
                  :labelCol="{
                    xs: { span: 24 },
                    sm: { span: 5 },
                  }"
                  :wrapperCol="{
                    xs: { span: 24 },
                    sm: { span: 12 },
                  }">
                  <select-project-input
                    v-model="queryParam.xmmc"
                    :proDisabled="true"
                    :isContractManager="true"
                    :projectType="'2'"/>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="业绩归属年度" :labelCol="labelCol">
                  <j-dict-select-tag placeholder="请选择业绩归属年度" v-model="queryParam.yjgsnd" dictCode="yjgsnd"/>
                </a-form-item>
              </a-col>

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="签订日期" :labelCol="labelCol">
                  <a-range-picker
                    format="YYYY-MM-DD"
                    :placeholder="['开始日期', '结束日期']"
                    v-model="qdrqRange"
                    @change="(dates, dateStrs) => { queryParam.qdrq_begin = dateStrs[0]; queryParam.qdrq_end = dateStrs[1] }"
                    style="width: 100%"/>
                </a-form-item>
              </a-col>

              <!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
              <!--              <a-form-item label="合同类型" :labelCol="labelCol">-->
              <!--                <j-dict-select-tag placeholder="请选择合同类型" v-model="queryParam.htlx" dictCode="htlx_type"/>-->
              <!--              </a-form-item>-->
              <!--            </a-col>-->

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="本次合同额" :labelCol="labelCol">
                  <a-input-number
                    :precision="0"
                    placeholder="请输入最小值"
                    class="query-group-cust"
                    v-model="queryParam.bchteBegin"
                    @change="(val) => this.bchteRange = parseInt(val)"
                    style="width: 46%"
                    :min="0"
                    :max="999999999"/>
                  -
                  <a-input-number
                    :precision="0"
                    placeholder="请输入最大值"
                    class="query-group-cust"
                    v-model="queryParam.bchteEnd"
                    style="width: 46%"
                    :min="bchteRange"
                    :max="999999999"/>
                </a-form-item>
              </a-col>

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item
                  label="签订单位"
                  :labelCol="{
                    xs: { span: 24 },
                    sm: { span: 5 },
                  }"
                  :wrapperCol="{
                    xs: { span: 24 },
                    sm: { span: 12 },
                  }">
                  <select-Company-input v-model="queryParam.qddw" placeholder="请选择签订单位"/>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item
                  label="业主单位"
                  :labelCol="{
                    xs: { span: 24 },
                    sm: { span: 5 },
                  }"
                  :wrapperCol="{
                    xs: { span: 24 },
                    sm: { span: 12 },
                  }">
                  <select-customer-input v-model="queryParam.yzdw" commercialType="1"/>
                </a-form-item>
              </a-col>

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item
                  label="经营团队"
                  :labelCol="{
                    xs: { span: 24 },
                    sm: { span: 5 },
                  }"
                  :wrapperCol="{
                    xs: { span: 24 },
                    sm: { span: 12 },
                  }">
                  <select-team-input v-model="queryParam.jytd" :tdlx="1" :teamType="0"/>
                </a-form-item>
              </a-col>

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="审核状态" :labelCol="labelCol">
                  <j-dict-select-tag placeholder="请选择审核状态" v-model="queryParam.bpmStatus" dictCode="bpm_status"/>
                </a-form-item>
              </a-col>

              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="申请人" :labelCol="labelCol">
                  <select-user-by-dep :multi="false" v-model="queryParam.proposer"/>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="申请部门" :labelCol="labelCol">
                  <j-select-depart placeholder="请选择申请部门" v-model="queryParam.proposerDeptId"/>
                </a-form-item>
              </a-col>
            </template>
            <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handleQuery" icon="search">查询</a-button>
                <a-button @click="qdrqRange=[],allSearchReset()" icon="reload" style="margin-left: 8px;">重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- table区域-begin -->
      <div>

        <a-table
          ref="table"
          :scroll="{x:scrollX}"
          bordered
          rowKey="id"
          :columns="defColumns"
          :components="draggableComponent"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange">
          <a slot="xmmc" slot-scope="text, record" @click="projectDetail(record.xmmc)">{{ text }}</a>
          <template slot="status" slot-scope="status">
            <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
          </template>
          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img
              v-else
              :src="getImgView(text)"
              height="25px"
              alt=""
              style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
              下载
            </a-button>
          </template>
          <a slot="htmc" :title="text" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
          <span slot="action" slot-scope="text, record">
            <a @click="onDetail(record)">详情</a>
          </span>

        </a-table>
      </div>
      <erp-project-contract-manager-form ref="contractForm" ></erp-project-contract-manager-form>
      <!-- 项目详情开始 -->
      <erp-project-report-modal  ref="projectModalForm"></erp-project-report-modal>
    </a-card>
    <template slot="footer">
      <a-button @click.stop="()=>{visible=false}">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
import ErpProjectContractManagerForm from './ErpProjectContractManagerForm'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import Ellipsis from '@/components/Ellipsis'
import { getAction } from '@/api/manage';
import { DragResizable } from '@/mixins/DragResizable'
export default {
  name: 'ErpOmcCollectContractManagerList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin,DragResizable],
  components: {
    ErpProjectReportModal,
    ErpProjectContractManagerForm,
    SelectCustomerInput,
    SelectTeamInput,
    SelectProjectInput,
    SelectUserByDep,
    SelectCompanyInput,
    Ellipsis
  },
  data() {
    return {
      queryParam: {
        htlx: '1'
      },
      visible: false,
      caId: 'undefined',
      labelCol: {
        style: {
        }
      },
      description: '合同管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          align: 'center',
          key: 'rowIndex',
          // fixed: 'left',
          width: 70,
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'htbh',
          // fixed: 'left',
          width: 150,
          ellipsis: true
        },
        {
          title: '合同名称',
          align: 'center',
          dataIndex: 'htmc',
          // fixed: 'left',
          width: 160,
          ellipsis: true,
          scopedSlots: { customRender: 'htmc' }
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'xmbh',
          width: 160,
          ellipsis: true
        },
        {
          title: '项目名称',
          align: 'center',
          scopedSlots: { customRender: 'xmmc' },
          dataIndex: 'xmmc_dictText',
          width: 160,
          ellipsis: true
        },

        {
          title: '业绩归属年度',
          align: 'center',
          dataIndex: 'yjgsnd_dictText',
          width: 150,
          ellipsis: true,
        },
        {
          title: '签订日期',
          align: 'center',
          dataIndex: 'qdrq',
          ellipsis: true,
          width: 150,
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '合同类型',
          align: 'center',
          dataIndex: 'htlx_dictText',
          width: 100,
          ellipsis: true
        },
        {
          title: '本次合同额(元)',
          align: 'center',
          dataIndex: 'bchte',
          width: 150,
          ellipsis: true,
        },
        {
          title: '签订单位',
          align: 'center',
          dataIndex: 'qddw_dictText',
          width: 150,
          ellipsis: true
        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'yzdw_dictText',
          width: 150,
          ellipsis: true
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'jytd_dictText',
          width: 150,
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
          width: 100,
          ellipsis: true

        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'proposerDeptId_dictText',
          width: 150,
          ellipsis: true
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'lx_dictText',
          width: 100,
          ellipsis: true
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
          width: 100,
          scopedSlots: { customRender: 'bpmStatus' }
          // fixed: 'right',
          // width: 90
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 60,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/omc/contractmanager/erpOmcContractManager/list',
        delete: '/api/erp/omc/contractmanager/erpOmcContractManager/delete',
        deleteBatch: '/api/erp/omc/contractmanager/erpOmcContractManager/deleteBatch',
        exportXlsUrl: '/api/erp/omc/contractmanager/erpOmcContractManager/exportXls',
        bizCount: '/api/erp/omc/contractmanager/erpOmcContractManager/bizCount',
        queryProjectById: '/api/erp/project/report/erpProjectReport/queryById'
      },
      dictOptions: {},
      superFieldList: [],
      qdrqRange: [],
      bchteRange: 0,
      disableMixinCreated: true
    }
  },
  created() {
     // 初始化字典配置 在自己页面定义
     this.initDictConfig()
      this.initColumns()
    this.resetScreenSize();
    this.getSuperFieldList();
    this.customKey = 'defColumns'
    this.defColumnswidth = this.defColumns.map(val => {
      return val.width
    })
  },
  computed: {
  },
  methods: {
    projectDetail(id) {
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            that.$refs.projectModalForm.getDetail(model);
            that.$refs.projectModalForm.title = '项目一览表';
          }
        })
      })
    },
    onDetail(record){
      this.$refs.contractForm.initData(record.id);
      this.$refs.contractForm.visible = true;
    },
    // 触发屏幕自适应
    resetScreenSize() {
      let screenWidth = document.body.clientWidth;
      if (screenWidth < 500) {
        this.scrollTrigger = { x: 800 };
      } else {
        this.scrollTrigger = {};
      }
    },
    handleCancel() {
      this.visible = false;
    },
    allSearchReset() {
      this.qdrqRange = null
      this.queryParam = {};
      this.bizTaskType = null
      this.queryParam.caId = this.caId
      this.loadData(1);
    },
    initData(val) {
      this.caId = val
      this.allSearchReset()
      this[this.customKey].forEach((val,index) => {
        val.width = this[this.customKey+'width'][index]
      })
    },
    getDetail(id) {
      this.$refs.contractForm.initData(id);
      this.$refs.contractForm.visible = true;
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'htbh', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'htlx', text: '合同类型', dictCode: 'htlx_type' })
      fieldList.push({ type: 'string', value: 'htmc', text: '合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmmc', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmbh', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jytd', text: '经营团队', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yjgsnd', text: '业绩归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'string', value: 'qddw', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmcjr', text: '项目承接人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzdw', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxr', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxfs', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'date', value: 'qdrq', text: '签订日期' })
      fieldList.push({ type: 'int', value: 'sfyz', text: '是否用印', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'yzlx', text: '印章类型', dictCode: 'yzlx_type' })
      fieldList.push({ type: 'int', value: 'yyfs', text: '用印份数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'glskht', text: '关联收款合同', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'skhtmc', text: '收款合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jf', text: '甲方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yf', text: '乙方', dictCode: '' })
      fieldList.push({ type: 'int', value: 'skhte', text: '收款合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtedx', text: '收款合同额大写', dictCode: '' })
      fieldList.push({ type: 'int', value: 'bchte', text: '本次合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bchtedx', text: '本次合同额大写', dictCode: '' })
      fieldList.push({ type: 'date', value: 'fwqx', text: '服务期限' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleReset() {
      this.qdrqRange = [];
      this.searchReset();
    },
    handleQuery() {
      // this.queryParam.bchte_begin = this.queryParam.bchte_begin * 100
      // this.queryParam.bchte_end = this.queryParam.bchte_begin * 100
      this.searchQuery()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
